package com.lambda.hybrid.handler;

import android.content.ClipboardManager;

import com.lambda.hybrid.Callback;

import org.json.JSONObject;

public class GetClipboardHandler extends AbstractHandler {
    private final ClipboardManager mClipboardMng;

    public GetClipboardHandler(ClipboardManager clipboard) {
        mClipboardMng = clipboard;
    }

    @Override
    public void onHandle(String data, Callback callback) throws Exception {
        CharSequence result = mClipboardMng.getText();
        JSONObject object = new JSONObject();
        if (result == null) {
            object.put("data", JSONObject.NULL);
        } else {
            object.put("data", result.toString());
        }
        callback.invoke(object.toString());
    }
}
